#pragma once

#include<iostream>
#include<string>
#include <functional>

class Reactor;

using handler_t = std::function<std::string(std::string&)>;
class Connection
{
public:
    Connection():_events(0),_owner(nullptr)
    {}

    void SetEvents(const uint32_t events)
    {
        _events = events;
    }

    uint32_t GetEvents()
    {
        return _events;
    }

    void SetOwner(Reactor* owner)
    {
        _owner = owner;
    }

    Reactor* GetOwner()
    {
        return _owner;
    }

    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Excepter() = 0;
    virtual int GetSockfd() = 0;

    void RegisterHandler(handler_t handler)
    {
        _handler = handler;
    }

    ~Connection(){}
private:
    uint32_t _events;//关心的事件
    Reactor* _owner;//回指指针,因为新连接是要添加到Reactor的map中管理的

    //fd、缓冲区、等交给子类具体实现...

public:
    handler_t _handler;
};